#ifndef CVX_CALIB3D_H
#define CVX_CALIB3D_H 1

#include "nvmath.h"
#include <vector>
#include "cvxImage.h"

using std::vector;

/*
	calibrate camera using 
	"Flexible camera calibration by viewing a plane from unknown orientations" ICCV1999
*/

class CvxCalib3d
{
public:
	/*	
		section 3.1 closed-form solution
	*/

	static bool closedFormSolution(const vector<Point3f> & objectPoints,
								   const vector<vector<Point2f> >& imagePoints,
								   const CvSize &imageSize,
								   CV_IN_OUT Mat& cameraMatrix,
								   CV_IN_OUT Mat& distCoeffs,
								   CV_OUT vector<Mat>& rvecs, CV_OUT vector<Mat>& tvecs,
								   bool computerExtrinsic);

	/************************************************************************/
	/* similar interface with opencv2.2
	   but change the code inside*/
	/************************************************************************/

	//! finds intrinsic and extrinsic camera parameters from several fews of a known calibration pattern.
	static CV_EXPORTS_W double calibrateCamera( const vector<vector<Point3f> >& objectPoints,
										 const vector<vector<Point2f> >& imagePoints,
										 Size imageSize,
										 CV_IN_OUT Mat& cameraMatrix,
										 CV_IN_OUT Mat& distCoeffs,
										 CV_OUT vector<Mat>& rvecs, CV_OUT vector<Mat>& tvecs,
										 int flags=0 );

	static double cvCalibrateCamera2( const CvMat* objectPoints,
									  const CvMat* imagePoints, const CvMat* npoints,
									  CvSize imageSize, CvMat* cameraMatrix, CvMat* distCoeffs,
									  CvMat* rvecs, CvMat* tvecs, int flags );

	//normalize the date before computer homography
	static void cvInitIntrinsicParams2D( const CvMat* objectPoints,
											 const CvMat* imagePoints, const CvMat* npoints,
											 CvSize imageSize, CvMat* cameraMatrix,
											 double aspectRatio );

};


#endif